import { Component, OnInit } from '@angular/core';
import { Singlepage } from '../../model/singlepage';
import { HttpClient } from '@angular/common/http';
import { ActivatedRoute, Router } from '@angular/router';
import { SinglepageService } from '../../service/singlepage.service';

@Component({
  selector: 'app-uploadsinglepage',
  templateUrl: './uploadsinglepage.component.html',
  styleUrls: ['./uploadsinglepage.component.css']
})
export class UploadsinglepageComponent implements OnInit {

sl:Array<Singlepage>;
  constructor(
 private http:HttpClient,
 private routerinfo:ActivatedRoute,
 private router:Router,
 private singlepageservice:SinglepageService
  ) { }

  ngOnInit() {
    this.loadSinglepageList();
  }

  private loadSinglepageList(){
    this.sl=new Array();
  
    this.singlepageservice.getSinglepageList()
    .then((data:any)=>{
      this.sl=data;
    })
  }
  
  
  addSinglepage(){
      this.router.navigate(['editSinglepage','add']);
        }
  
  updateSinglepage(id:string){
      this.router.navigate(['editSinglepage',id]);
        }
  
        deleteSinglepage(id:string){
       this.singlepageservice.deleteSinglepage(id)
       .then((flag:boolean)=>{
         if(flag==true){
           this.loadSinglepageList();
         }else{
           alert("操作异常，请刷新后重试");
         }
       })
     }

  

}
